﻿
using JshRCSWebApi.Infrastructure.Domain.DTO.SysService;

namespace JshRCSWebApi.API.Controllers.SysService
{
    public class DepartmentController : BaseController
    {
        private readonly DepartmentService _departmentService;
        public DepartmentController(IHttpContextAccessor httpContextAccessor,DepartmentService departmentService) : base(httpContextAccessor)
        {
            this._departmentService = departmentService;
        }

        /// <summary>
        /// 获取部门列表(分页+树形显示)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetDepartmentList([FromBody] DepartmentSearchDTO searchDTO)
            => await Task.Run(async () => await _departmentService.GetDepartmentList(searchDTO));

        /// <summary>
        /// 获取部门名称和ID集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetDepartmentNameAndIDList()
            => await Task.Run(async () => await _departmentService.GetDepartmentNameAndIDList());

        /// <summary>
        /// 查询部门列表（分页 + 非树形）
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetDepartmentListByMutiCondtion([FromBody] DepartmentSearchByConditionDTO searchDTO)
            => await Task.Run(async () => await _departmentService.GetDepartmentListByMutiCondtion(searchDTO));

        /// <summary>
        /// 新增部门
        /// </summary>
        /// <param name="addDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddDepartment([FromBody] DepartmentAddDTO addDTO)
            => await Task.Run(async () => await _departmentService.AddDepartment(addDTO, Convert.ToInt32(GetUser("ID"))));

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DeleteDepartment(int ID)
            => await Task.Run(async () => await _departmentService.DeleteDepartment(ID));

        /// <summary>
        /// 修改部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> UpdateDepartment([FromBody] DepartmentUpdateDTO updateDTO)
            => await Task.Run(async () => await _departmentService.UpdateDepartment(updateDTO, Convert.ToInt32(GetUser("ID"))));

        /// <summary>
        /// 获取部门管理者
        /// </summary>
        /// <param name="sdid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> SelectDepartmentManager(int sdid)
            => await Task.Run(async () => await _departmentService.SelectDepartmentManager(sdid));

        /// <summary>
        /// 获取部门用户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> SelectDepartmentUser(int sdid)
            => await Task.Run(async () => await _departmentService.SelectDepartmentUser(sdid));
    }
}
